package com.meetingshow.utils;

import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.meetingshow.commu.uiservice.IUIAnswerService;
import com.meetingshow.commu.uiservice.IUIQuestionService;
import com.meetingshow.meeting.uiservice.IUICityService;
import com.meetingshow.meeting.uiservice.IUIIndustryService;
import com.meetingshow.meeting.uiservice.IUIMeetingService;
import com.meetingshow.meeting.uiservice.IUIMeetingTypeService;
import com.meetingshow.meeting.uiservice.IUITopicService;
import com.meetingshow.meeting.uiservice.IUIUserFollowService;
import com.meetingshow.privilege.uiservice.IUIEventService;
import com.meetingshow.privilege.uiservice.IUIPriUserFollowService;
import com.meetingshow.privilege.uiservice.IUIUserService;
import com.meetingshow.service.meeting.IMeetingSVC;
import com.meetingshow.service.user.IUserSVC;
import com.meetingshow.weibo.uiservice.IUIWeiboService;

public class UIServiceFactory {
    
    private final static Logger logger = Logger.getLogger(UIServiceFactory.class); 

    private static ApplicationContext ctx = null;
    
    static {
        try{
        ctx = new ClassPathXmlApplicationContext(
                new String[] { "applicationContext.xml" });
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
    }

    public static ApplicationContext getContext() {
        return ctx;
    }

    public static IUserSVC getUserSVC() {
        try {
            if (getContext() != null)
                return (IUserSVC) ctx.getBean("userSVC");
            return null;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return null;
        }
    }

    public static IMeetingSVC getMeetingSVC() {
        try {
            if (getContext() != null)
                return (IMeetingSVC) ctx.getBean("meetingSVC");
            return null;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return null;
        }
    }

    public static IUIUserService getUIUserService() {
        try {
            if (getContext() != null)
                return (IUIUserService) ctx.getBean("uiUserService");
            return null;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return null;
        }
    }
    
    public static IUIPriUserFollowService getUIPriUserFollowService() {
        try {
            if (getContext() != null)
                return (IUIPriUserFollowService) ctx.getBean("uiPriUserFollowService");
            return null;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return null;
        }
    }
    
    public static IUIWeiboService getUIWeiboService() {
        try {
            if (getContext() != null)
                return (IUIWeiboService) ctx.getBean("uiWeiboService");
            return null;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return null;
        }
    }
    
    public static IUIMeetingService getUIMeetingService() {
        try {
            if (getContext() != null)
                return (IUIMeetingService) ctx.getBean("uiMeetingService");
            return null;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            e.printStackTrace();
            return null;
        }
    }
    
    public static IUIMeetingTypeService getUIMeetingTypeService() {
        try {
            if (getContext() != null)
                return (IUIMeetingTypeService) ctx.getBean("uiMeetingTypeService");
            return null;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return null;
        }
    }
    
    public static IUIUserFollowService getUIUserFollowService() {
        try {
            if (getContext() != null)
                return (IUIUserFollowService) ctx.getBean("uiUserFollowService");
            return null;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return null;
        }
    }
    
    public static IUITopicService getUITopicService() {
        try {
            if (getContext() != null)
                return (IUITopicService) ctx.getBean("uiTopicService");
            return null;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return null;
        }
    }
    
    public static IUIAnswerService getUIAnswerService() {
        try {
            if (getContext() != null)
                return (IUIAnswerService) ctx.getBean("uiAnswerService");
            return null;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return null;
        }
    }
    
    public static IUIQuestionService getUIQuestionService() {
        try {
            if (getContext() != null)
                return (IUIQuestionService) ctx.getBean("uiQuestionService");
            return null;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return null;
        }
    }

    public static IUICityService getUICityService() {
        try {
            if (getContext() != null)
                return (IUICityService) ctx.getBean("uiCityService");
            return null;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return null;
        }
    }

    public static IUIIndustryService getUIIndustryService() {
        try {
            if (getContext() != null)
                return (IUIIndustryService) ctx.getBean("uiIndustryService");
            return null;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return null;
        }
    }
    
    public static IUIEventService getUIEventService() {
        try {
            if (getContext() != null)
                return (IUIEventService) ctx.getBean("uiEventService");
            return null;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return null;
        }
    }
}
